home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / superman.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  5KB  |  221 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw/superman.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10.  
  11. size_t supes_videoram_size;
  12. size_t supes_attribram_size;
  13.  
  14. unsigned char *supes_videoram;
  15. unsigned char *supes_attribram;
  16. //static unsigned char *dirtybuffer;        /* foreground */
  17. //static unsigned char *dirtybuffer2;        /* background */
  18.  
  19. int superman_vh_start (void)
  20. {
  21.     return 0;
  22. }
  23.  
  24. void superman_vh_stop (void)
  25. {
  26. }
  27.  
  28. /*************************************
  29.  *
  30.  *        Foreground RAM
  31.  *
  32.  *************************************/
  33.  
  34. WRITE_HANDLER( supes_attribram_w )
  35. {
  36.    int oldword = READ_WORD (&supes_attribram[offset]);
  37.    int newword = COMBINE_WORD (oldword, data);
  38.  
  39.    if (oldword != newword)
  40.    {
  41.         WRITE_WORD (&supes_attribram[offset], data);
  42. //        dirtybuffer2[offset/2] = 1;
  43.    }
  44. }
  45.  
  46. READ_HANDLER( supes_attribram_r )
  47. {
  48.    return READ_WORD (&supes_attribram[offset]);
  49. }
  50.  
  51.  
  52.  
  53. /*************************************
  54.  *
  55.  *        Background RAM
  56.  *
  57.  *************************************/
  58.  
  59. WRITE_HANDLER( supes_videoram_w )
  60. {
  61.    int oldword = READ_WORD (&supes_videoram[offset]);
  62.    int newword = COMBINE_WORD (oldword, data);
  63.  
  64.    if (oldword != newword)
  65.    {
  66.         WRITE_WORD (&supes_videoram[offset], data);
  67. //        dirtybuffer[offset/2] = 1;
  68.    }
  69. }
  70.  
  71. READ_HANDLER( supes_videoram_r )
  72. {
  73.    return READ_WORD (&supes_videoram[offset]);
  74. }
  75.  
  76.  
  77. void superman_update_palette (void)
  78. {
  79.     unsigned short palette_map[32]; /* range of color table is 0-31 */
  80.     int i;
  81.  
  82.     memset (palette_map, 0, sizeof (palette_map));
  83.  
  84.     /* Find colors used in the background tile plane */
  85.     for (i = 0; i < 0x400; i += 0x40)
  86.     {
  87.         int i2;
  88.  
  89.         for (i2 = i; i2 < (i + 0x40); i2 += 2)
  90.         {
  91.             int tile;
  92.             int color;
  93.  
  94.             color = 0;
  95.  
  96.             tile = READ_WORD (&supes_videoram[0x800 + i2]) & 0x3fff;
  97.             if (tile)
  98.                 color = READ_WORD (&supes_videoram[0xc00 + i2]) >> 11;
  99.  
  100.             palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
  101.  
  102.         }
  103.     }
  104.  
  105.     /* Find colors used in the sprite plane */
  106.     for (i = 0x3fe; i >= 0; i -= 2)
  107.     {
  108.         int tile;
  109.         int color;
  110.  
  111.         color = 0;
  112.  
  113.         tile = READ_WORD (&supes_videoram[i]) & 0x3fff;
  114.         if (tile)
  115.             color = READ_WORD (&supes_videoram[0x400 + i]) >> 11;
  116.  
  117.         palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
  118.     }
  119.  
  120.     /* Now tell the palette system about those colors */
  121.     for (i = 0;i < 32;i++)
  122.     {
  123.         int usage = palette_map[i];
  124.         int j;
  125.  
  126.         if (usage)
  127.         {
  128.             palette_used_colors[i * 16 + 0] = PALETTE_COLOR_TRANSPARENT;
  129.             for (j = 1; j < 16; j++)
  130.                 if (palette_map[i] & (1 << j))
  131.                     palette_used_colors[i * 16 + j] = PALETTE_COLOR_USED;
  132.                 else
  133.                     palette_used_colors[i * 16 + j] = PALETTE_COLOR_UNUSED;
  134.         }
  135.         else
  136.             memset(&palette_used_colors[i * 16],PALETTE_COLOR_UNUSED,16);
  137.     }
  138.  
  139.     palette_recalc ();
  140.  
  141. }
  142.  
  143. void superman_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
  144. {
  145.     int i;
  146.  
  147.     superman_update_palette ();
  148.  
  149.     osd_clearbitmap(bitmap);
  150.  
  151.     /* Refresh the background tile plane */
  152.     for (i = 0; i < 0x400; i += 0x40)
  153.     {
  154.         int x1, y1;
  155.         int i2;
  156.  
  157.         x1 = READ_WORD (&supes_attribram[0x408 + (i >> 1)]);
  158.         y1 = READ_WORD (&supes_attribram[0x400 + (i >> 1)]);
  159.  
  160.         for (i2 = i; i2 < (i + 0x40); i2 += 2)
  161.         {
  162.             int tile;
  163.  
  164.             tile = READ_WORD (&supes_videoram[0x800 + i2]) & 0x3fff;
  165.             if (tile)
  166.             {
  167.                 int x, y;
  168.  
  169.                 x = (        x1 + ((i2 & 0x03) << 3))  & 0x1ff;
  170.                 y = ((265 - (y1 - ((i2 & 0x3c) << 2))) &  0xff);
  171.  
  172. //                if ((x > 0) && (y > 0) && (x < 388) && (y < 272))
  173.                 {
  174.                     int flipx = READ_WORD (&supes_videoram[0x800 + i2]) & 0x4000;
  175.                     int flipy = READ_WORD (&supes_videoram[0x800 + i2]) & 0x8000;
  176.                     int color = READ_WORD (&supes_videoram[0xc00 + i2]) >> 11;
  177.  
  178.                     /* Some tiles are transparent, e.g. the gate, so we use TRANSPARENCY_PEN */
  179.                     drawgfx(bitmap,Machine->gfx[0],
  180.                         tile,
  181.                         color,
  182.                         flipx,flipy,
  183.                         x,y,
  184.                         &Machine->drv->visible_area,
  185.                         TRANSPARENCY_PEN,0);
  186.                 }
  187.             }
  188.         }
  189.     }
  190.  
  191.     /* Refresh the sprite plane */
  192.     for (i = 0x3fe; i >= 0; i -= 2)
  193.     {
  194.         int sprite;
  195.  
  196.         sprite = READ_WORD (&supes_videoram[i]) & 0x3fff;
  197.         if (sprite)
  198.         {
  199.             int x, y;
  200.  
  201.             x = (      READ_WORD (&supes_videoram [0x400 + i]))  & 0x1ff;
  202.             y = (250 - READ_WORD (&supes_attribram[i        ]))  & 0xff;
  203.  
  204. //            if ((x > 0) && (y > 0) && (x < 388) && (y < 272))
  205.             {
  206.                 int flipy = READ_WORD (&supes_videoram[i]) & 0x4000;
  207.                 int flipx = READ_WORD (&supes_videoram[i]) & 0x8000;
  208.                 int color = READ_WORD (&supes_videoram[0x400 + i]) >> 11;
  209.  
  210.                 drawgfx(bitmap,Machine->gfx[0],
  211.                     sprite,
  212.                     color,
  213.                     flipx,flipy,
  214.                     x,y,
  215.                     &Machine->drv->visible_area,
  216.                     TRANSPARENCY_PEN,0);
  217.             }
  218.         }
  219.     }
  220. }
  221.